<?php

/**
 * This is the model class for table "aekdroid_details".
 *
 * The followings are the available columns in table 'aekdroid_details':
 * @property integer $id
 * @property integer $type
 * @property string $min
 * @property string $player
 * @property string $comment
 * @property integer $side
 * @property integer $deleted
 */
class Detail extends CActiveRecord
{
    const GOAL = 0;
    const HOME = 0;
    const VISITOR = 1;
    public static $SIDE = array("Γηπεδούχος","Φιλοξενούμενος");
    public static $TYPES = array("Γκολ","Κίτρινη","2η Κίτρινη","Κόκκινη","Δοκάρι","Χαμένο πέναλτυ","Είσοδος","Έξοδος");
    public $min_view;
    
    
	/**
	 * Returns the static model of the specified AR class.
	 * @return Detail the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'aekdroid_details';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('match_id, type, side, min, player', 'required'),
			array('type, side, deleted', 'numerical', 'integerOnly'=>true),
			array('min', 'length', 'max'=>10),
			array('player, comment', 'length', 'max'=>45),
			array('match_id','safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('match_id, _id, type, min, player, comment, side, deleted', 'safe', 'on'=>'search'),
		);
	}
	
	public function afterFind(){
	    $t = split(".", $this->min); 
	    if(sizeof($t)>1 && ($t[0]==45)||$t[0]==90 || $t[0]==105 || $t[0]==120){
	        $this->min_view = substr($this->min, 0,$pos)."'"."+";
	    } else {
	        $this->min_view = (integer)$this->min ."'";
	    }
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		 return array(
        'match' => array(self::BELONGS_TO, 'Match', 'match_id'),
    );
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'_id' => 'ID',
			'type' => 'Type',
			'min' => 'Min',
			'player' => 'Player',
			'comment' => 'Comment',
			'side' => 'Side',
			'deleted' => 'Deleted',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('_id',$this->_id);
		$criteria->compare('type',$this->type);
		$criteria->compare('min',$this->min,true);
		$criteria->compare('player',$this->player,true);
		$criteria->compare('comment',$this->comment,true);
		$criteria->compare('side',$this->side);
		$criteria->compare('deleted',$this->deleted);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}